package dt.member;

import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class memberInfoAction extends ActionSupport {
	
	public static Reader reader;  // ���� ��Ʈ���� ���� reader
	public static SqlMapClient sqlMapper; // SqlMapClient API�� ����ϱ� ���� sqlMapper ��ü

	private memberVO paramClass;  // �Ķ���͸� ������ ��ü
	private memberVO resultClass; // ���� ��� ���� ������ ��ü
	
	//����
	public memberInfoAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); //sqlMapConfig.xml ������ ���������� �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); //sqlMapConfig.xml ������ ����� sqlMapper ��ü ��
		reader.close();
	}
	
	// ȸ������ ���� �׼�
	public String execute() throws Exception {
		
		// �Ķ���Ϳ� ����Ʈ ��ü ��
		paramClass = new memberVO();
		resultClass = new memberVO();
		
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session = context.getSession();

		//�̸� ������ �ٿ��, �ش� ������ id���� ������ memberVO�� DB�� �ڷḦ ������
		if(session.size() > 0){
			String id=(String)session.get("id");
			resultClass = (memberVO) sqlMapper.queryForObject("getMember", id);
			return SUCCESS;
		}
		else {
			return LOGIN;
		}

	}

	public static Reader getReader() {
		return reader;
	}

	public static void setReader(Reader reader) {
		memberInfoAction.reader = reader;
	}

	public static SqlMapClient getSqlMapper() {
		return sqlMapper;
	}

	public static void setSqlMapper(SqlMapClient sqlMapper) {
		memberInfoAction.sqlMapper = sqlMapper;
	}

	public memberVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(memberVO paramClass) {
		this.paramClass = paramClass;
	}

	public memberVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(memberVO resultClass) {
		this.resultClass = resultClass;
	}

}
